﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using Zeus.Web.Classes;
using Zeus.Classes;
using MenuControl;
using System.Xml.Linq;

namespace Zeus.UserControls
{
    public partial class menu_file_UserControl : UserControl
    {
        public menu_file_UserControl()
        {
            InitializeComponent();
        }

        private void MenuItem_Click_New(object sender, RoutedEventArgs e)
        {
            System.Windows.Browser.HtmlPage.Window.Alert("you pressed: " + (sender as MenuItem).MenuText);
        }

        private void MenuItem_Click_Open(object sender, RoutedEventArgs e)
        {
            ShowOpenFileDialog();
        }

        private void MenuItem_Click_Save(object sender, RoutedEventArgs e)
        {
            System.Windows.Browser.HtmlPage.Window.Alert("you pressed: " + (sender as MenuItem).MenuText);
        }

        private void MenuItem_Click_SaveAs(object sender, RoutedEventArgs e)
        {
            ShowSaveFileDialog();
        }

        private void ShowOpenFileDialog()
        {
            OpenFileDialog OpenDlg = new OpenFileDialog();
            OpenDlg.Filter = "Text Files|*.txt|Log Files|*.log|All Files|*.*";
            OpenDlg.FilterIndex = 2;
            OpenDlg.ShowDialog();
        }

        private void ShowSaveFileDialog()
        {
            SaveFileDialog SaveDlg = new SaveFileDialog();
            SaveDlg.ShowDialog();
        }

        private void MenuItem_click_Import_Sound(object sender, RoutedEventArgs e)
        {

            OpenFileDialog ofd = new OpenFileDialog();
            if ((bool)ofd.ShowDialog() == true)
            {

                Stream Stream_sound = ofd.File.OpenRead();
                SoundDocument SoundDocument_1 = new SoundDocument(Stream_sound);
                soundView SoundView_1 = new soundView(SoundDocument_1);
                SoundDocument_1.Lview.Add(SoundView_1);
                SoundView_1.Show();
            }
        }

        private void MenuItem_Click_OpenImage(object sender, RoutedEventArgs e)
        {
            OpenFileDialog OpenImage = new OpenFileDialog();
            OpenImage.Filter = "JPEG Files (*.jpg;*.jpeg)|*.jpg;*.jpeg | All Files (*.*)|*.*";
            OpenImage.ShowDialog();
            Stream Stream = OpenImage.File.OpenRead();      //it crached if i closed dialog without chooseing image

            ImageDocumant IDoc = new ImageDocumant(Stream);
            DisplayImageView IView = new DisplayImageView(IDoc);
            IDoc.Lview.Add(IView);

            IView.Show();
        }

        private void MenuItem_Click_openvideo(object sender, RoutedEventArgs e)
        {
            OpenFileDialog vdialog = new OpenFileDialog();
            vdialog.Filter = "video file(.wmv)|*.wmv";
            if ((bool)vdialog.ShowDialog())
            {

                Stream st = vdialog.File.OpenRead();
                videoDocument vdoc = new videoDocument(st);
                viewvideo Vview = new viewvideo(vdoc);
                Vview.Show();

            }
            else
            {
                MessageBox.Show("u didn't select a file");
            }
        }
        private void MenuItem_Click_6(object sender, RoutedEventArgs e)
        {
            List<XElement> list = NewProject();
            NewProjectChildWindow n = new NewProjectChildWindow(list);
            n.Show();
        }

        private List<XElement> NewProject()
        {
            XDocument doc = XDocument.Load("ProjectTypes.xml");
            var ProjectTypes =
            (from project in doc.Descendants() where project.Name == "type" select project).ToList();
            return ProjectTypes;
        }

        private void MenuItem_Click_OpenProject(object sender, RoutedEventArgs e)
        {
            OpenProjectChildWindow Window = new OpenProjectChildWindow();
            Window.Show();
        }

    }
    
        
}
